Skip to content

Host core: a comparison session that keeps settings across pairs - #114

Merged
agorischek merged 5 commits into
mainfrom
comparison-session
Nov 21, 2026
Merged

agorischek merged 5 commits into
mainfrom
comparison-session

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Stacked on #113 (keyboard), which is stacked on #112 (the view model). This is item G6 of the headless-host plan.

Why

A pair picker's view remounts for each new comparison, so each explorer kept the person's settings above it, in its own copy. The copies were in ui/explorer.tsx, vscode-ui/src/explorer.tsx and Primer's explorer.tsx, about 40–60 lines each, and they had drifted:

Default UI VS Code UI Primer
Loop and connector kept across pairs no (reset with each pair) yes yes
Initial mode kept to the modes features offer no yes yes
Default scope Changes Changes All

The user decided the default scope is Changes everywhere. A surface may still choose otherwise through an option: consistent defaults, but configurable.

What's in the core now

  • useComparisonSession(options) returns ComparisonSessionSettings, controlled values with stable handlers, ready to spread into useProjection or a view. It covers mode (absent until chosen, so the renderer's default applies), swipePosition, highlighting, changesOnly, search, connector and loop.

  • comparisonSessionDefaults(options) is pure, and is where each setting starts:

    • its initial… option;
    • else the definition's presentation;
    • else the shared default. Changes is the scope default; initialChangesOnly changes it.

    An initial mode the features don't offer gives way to the first they offer.

Both explorers now call the hook and spread the result. Both gain initialChangesOnly.

Behaviour changes

  • Default UI's ComparisonExplorer:
    • loop and the connector now carry across pairs, as in the VS Code UI;
    • an initial mode that features.modes excludes falls back to the first offered.

Primer adopts the hook after the pin bump. Meanwhile, a private PR moves its default scope to Changes.

Docs and tests

  • docs/guides/host-core.md documents the hook and its defaults, next to useComparisonPair.
  • packages/host/core/test/comparison-session.test.mjs (node:test, 3 tests) covers:
    • the shared defaults;
    • presentation seeding, with initial… overriding it;
    • mode clamping to the features.

Run locally:

  • tools check --fast: pass.
  • tsc for core and the VS Code UI: pass.
  • The new tests: 3/3.

The browser suites run in CI.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The handler stores rejected changes to controlled settings, causing stale requests to take effect when the controlled prop is later removed.

1 open issue
What changed in this PR

Adds a shared comparison session to the headless host core, replacing duplicated explorer state so user settings persist across comparison pairs.

Changes:

  • Introduces useComparisonSession, shared defaults, and public types.
  • Migrates both explorers to the hook, adds initialChangesOnly, and aligns initial-mode handling with offered features.
  • Documents session usage and adds tests for defaults, presentation overrides, and mode restrictions.
File Description
packages/​host/​vscode-ui/​src/​explorer.tsx Replaces local settings state with the shared session.
packages/​host/​core/​test/​comparison-session.test.mjs Tests defaults, overrides, and initial-mode restrictions.
packages/​host/​core/​src/​ui/​explorer.tsx Adopts the session, including loop and connector persistence.
packages/​host/​core/​src/​index.ts Exports session helpers and types.
packages/​host/​core/​src/​comparison-session.ts Implements session defaults, state, and stable handlers.
docs/​guides/​host-core.md Documents session integration and configurable defaults.

Review effort: Balanced

@agorischek
agorischek force-pushed the comparison-session branch 2 times, most recently from 5e1c6d8 to c8b3d8b Compare November 21, 2026 01:37
@agorischek
agorischek force-pushed the headless-keys branch 2 times, most recently from 1378b59 to cd6a8c1 Compare November 21, 2026 15:19
@agorischek
agorischek force-pushed the comparison-session branch 2 times, most recently from 971f433 to d3a7b0c Compare November 21, 2026 18:28
agorischek and others added 4 commits November 21, 2026 11:07
…y UI

The default UI, the VS Code UI and Primer each had their own Space-to-play handler, with different lists of elements
that keep Space and different rules for held keys and enclosing dialogs, their own play-button naming, and three
copies of the arrow, Home and End rule for radio groups and tabs. The core now has them, framework-free:

- `handlePlaybackShortcut` and `isPlaybackShortcut`, with `spaceKeeping` and a `keeps` option for a design system's
  custom elements: one press, one toggle; a Space-keeping element that encloses the listener doesn't count; a key
  from a portaled overlay is never the shortcut;
- `rovingIndex(key, index, count, orientation?)`;
- `playButton(projection, beforeLabel, afterLabel)`: `{action, direction, label}`.

`spaceTogglesPlayback`, `playLabel`, `handlePlaybackKey` and `playButtonState` keep their names and use them.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A pair picker's view remounts for each new comparison, so the default UI's, the VS Code UI's and Primer's explorers
each kept the person's settings above it in their own copy, and the copies had drifted: only the VS Code UI and
Primer kept loop and the connector, only the VS Code UI kept the initial mode to the modes offered, and Primer opened
in All while the others opened in Changes.

`useComparisonSession` (with the pure `comparisonSessionDefaults`) keeps the mode, the swipe divider, highlighting, the
scope, find, the connector and loop. Each starts from its `initial…` option, else the definition's `presentation`,
else one shared default (the Changes scope among them), and each is controllable. Both explorers use it, and gain
`initialChangesOnly`. The default UI's explorer now keeps loop and the connector across pairs too.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…en a change is refused

A setting the embedder controls is only requested, as `useControllable` does: the session no longer stores the
change, so a refused one doesn't surface once the setting is no longer controlled.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Base automatically changed from headless-keys to main November 21, 2026 19:46
@agorischek
agorischek merged commit 42a5441 into main Nov 21, 2026
46 checks passed
@agorischek
agorischek deleted the comparison-session branch November 21, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants